package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Buyrecord;
import cn.wolfcode.crm.domain.SystemDictionary;
import cn.wolfcode.crm.qo.BuyrecordQueryObject;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.BuyrecordService;
import cn.wolfcode.crm.service.SystemDictionaryService;
import cn.wolfcode.crm.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/buyrecord")
public class BuyrecordController {
    @Autowired
    private BuyrecordService buyrecordService;
    @Autowired
    private SystemDictionaryService systemDictionaryService;

    @RequestMapping("/list")
    public String list(Model model , @ModelAttribute("qo" )BuyrecordQueryObject qo) {
        PageInfo<Buyrecord> pageInfo = buyrecordService.query(qo);
        model.addAttribute("pageInfo", pageInfo);

     /*   systemDictionaryService.queryBysystemDictionarysn();*/

        return "/buyrecord/list";
    }

    @RequestMapping("/input")
    public String input(Model model,Long id) {
        if (id != null) {
            Buyrecord buyrecord = buyrecordService.selectByPrimaryKey(id);
            model.addAttribute("buyrecord",buyrecord);
        }
        return "/buyrecord/input";

    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Buyrecord buyrecord) {

        try {
           if (buyrecord.getId()!=null) {
               buyrecordService.updateByPrimaryKey(buyrecord);
           }else {
               buyrecordService.insert(buyrecord);
           }

       }catch (Exception e){
           return new JsonResult(false,"保存或者修改失败");
       }
        return new JsonResult(true,"保存或者修改成功");





    }


}
